"""
    用于任务查看后的信息编辑，如编辑任务，导出配置，设置标注团队，修改标注团队，数据上传，任务开始，任务结束，任务删除等功能
"""
import time

from automatic import page
from automatic.base.base import Base
from automatic.base.get_logger import GetLogger
from automatic.tools.file_upload import FileUpload

log=GetLogger().get_logger()

class PageEditTask(Base):
    #点击编辑任务按钮
    def page_click_edit_task(self):
        log.info("[page_edit_task]:对{}元素进行点击操作".format(page.edit_task))
        self.base_click(page.edit_task)

    #编辑任务的保存按钮
    def page_click_save_button(self):
        log.info("[page_edit_task]:对{}元素进行点击操作".format(page.task_save))
        self.base_click(page.task_save)

    #点击预览配置
    def page_click_look_config(self):
        log.info("[page_edit_task]:对{}元素进行点击操作".format(page.task_look_config_button))
        self.base_click(page.task_look_config_button)

    #获取预览配置信息
    def page_get_look_config_err_info(self):
        log.info("[page_edit_task]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    #点击导出配置按钮
    def page_click_export_config(self):
        log.info("[page_edit_task]:对{}元素进行点击操作".format(page.task_export_config_button))
        self.base_click(page.task_export_config_button)

    #任务创建完成后进行数据配置
    #点击数据配置
    def page_click_add_data(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.data_add_button))
        self.base_click(page.data_add_button)

    # #点击任务的查看操作
    # #在page_task_list.py中实现
    # def page_click_task_check(self):
    #     log.info("[page_add_data]:正在对{}元素进行点击操作".format(page.first_task_check_button))
    #     self.base_click(page.first_task_check_button)

    #点击 点击上传
    def page_click_text_confirm(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.data_text_primary))
        self.base_click(page.data_text_primary)

    #上传数据文件
    @staticmethod
    def add_data_input_filepath(filepath):
        log.info("[page_edit_data]:正在输入数据文件:{}".format(filepath))
        FileUpload.upload_file(filepath)

    #点击确定按钮
    def page_click_data_confirm(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.data_confirm))
        self.base_click(page.data_confirm)

    #获取数据上传成功后的提示信息
    def page_get_data_add_success_info(self):
        log.info("[page_edit_data]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    #点击清空按钮，清空数据信息
    def page_click_data_clear(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.data_clear))
        self.base_click(page.data_clear)

    #点击是否确认清空数据的按钮
    def page_click_data_clear_confirm(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.data_clear_confirm))
        self.base_click(page.data_clear_confirm)

    #获取清空数据成功后的提示信息
    def page_get_data_clear_success_info(self):
        log.info("[page_edit_data]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    #填写答题倒计时
    def page_input_answer_countdown(self,countdown):
        log.info("[page_edit_data]:正在对{}元素进行输入答题倒计时：{}操作".format(page.data_answer_countdown,countdown))
        self.base_input(page.data_answer_countdown,countdown)

    # 选择标注团队
    def page_click_answer_team(self,team_name):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.data_answer_team))
        self.base_click(page.data_answer_team)
        time.sleep(2)
        #动态构造团队选项的定位器
        team_locator=(page.data_one_of_answer_team[0],page.data_one_of_answer_team[1].format(team_name))
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(team_locator))
        self.base_click(team_locator)
        time.sleep(2)
        self.base_click(page.data_answer_team)
    #非动态选择
    # def page_click_answer_team(self):
    #     log.info("[page_add_data]:正在对{}元素进行点击操作".format(page.data_answer_team))
    #     self.base_click(page.data_answer_team)
    #     log.info("[page_add_data]:正在对{}元素进行点击操作".format(page.data_one_of_answer_team))
    #     self.base_click(page.data_one_of_answer_team)
    #     time.sleep(2)
    #     self.base_click(page.data_answer_team)

    #点击开始任务按钮
    def page_click_start_task(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.start_task_button))
        self.base_click(page.start_task_button)

    #获取任务开始的提示信息
    def page_get_start_task_info(self):
        log.info("[page_edit_data]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    """
        任务开始后
    """
    #点击数据上传按钮
    def page_task_start_click_add_data(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_start_data_add))
        self.base_click(page.task_start_data_add)

    #点击 点击上传
    def page_task_start_click_text_confirm(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_start_text_primary))
        self.base_click(page.task_start_text_primary)

    #点击修改团队的修改按钮
    def page_click_team_edit(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_team_edit))
        self.base_click(page.task_team_edit)

    #点击确定按钮
    def page_click_team_edit_confirm(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_team_edit_confirm))
        self.base_click(page.task_team_edit_confirm)

    #所有提示信息
    def page_message_info(self):
        log.info("[page_edit_data]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    #点击修改取消按钮
    def page_click_edit_close(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_team_edit_close))
        self.base_click(page.task_team_edit_close)

    #点击搜索框
    def page_click_name_search(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_name_search))
        self.base_click(page.task_name_search)

    #点击搜索按钮
    def page_click_search_button(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_name_search_button))
        self.base_click(page.task_name_search_button)

    #点击统计分析
    def page_click_analyse(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_state_analyse))
        self.base_click(page.task_state_analyse)

    #点击数据分布
    def page_click_data_distribute(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_data_distribute))
        self.base_click(page.task_data_distribute)

    #选择针对项1,2(针对对话里每条回复，针对对话里的每个提问)
    def page_click_conversation(self,conversation_number):
        number=(page.task_in_conversation[0],page.task_in_conversation[1].format(conversation_number))
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(number))
        self.base_click(number)

    #针对整段内容/对话
    def page_click_content_conversation(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_content_in_conversation))
        self.base_click(page.task_content_in_conversation)

    #点击数据筛选
    def page_click_data_filter(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_data_filter))
        self.base_click(page.task_data_filter)

    #选择标注结果对比1,2(单题标注结果，源题多结果对比）
    def page_click_result(self,result_number):
        number=(page.task_result[0],page.task_result[1].format(result_number))
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(number))
        self.base_click(number)

    #设置筛选信息1,2,3(模块，题目，选项)
    def page_click_frame_select(self,frame_number):
        number=(page.task_frame_select[0],page.task_frame_select[1].format(frame_number))
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(number))
        self.base_click(number)

    #选择选项
    def page_click_task_selection(self,selection_title):
        selection=(page.task_selection[0],page.task_selection[1].format(selection_title))
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(selection))
        self.base_click(selection)

    #关闭统计分析
    def page_click_close_analyse(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_close_analyse))
        self.base_click(page.task_close_analyse)

    #悬停查看题目
    def page_move_to_check_question(self):
        self.base_move_to_element(page.task_check_question)

    #点击单题展示
    def page_click_single_question(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_single_question))
        self.base_click(page.task_single_question)

    #点击源题组合展示
    def page_click_multiple_question(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_multiple_questions))
        self.base_click(page.task_multiple_questions)

    #关闭内容对比
    def page_click_close_content_compare(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_close_content_compare))
        self.base_click(page.task_close_content_compare)

    #点击换一题
    def page_click_change_subject(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_change_subject))
        self.base_click(page.task_change_subject)

    #获取提示信息
    def page_get_change_success_info(self):
        log.info("[page_edit_data]:正在获取{}元素的文本信息".format(page.messages_info))
        return self.base_get_text(page.messages_info)

    #悬停下载
    def page_move_to_download(self):
        self.base_move_to_element(page.task_download)

    #点击导出下载量
    def page_click_export_downloads(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_export_downloads))
        self.base_click(page.task_export_downloads)

    #点击结束任务
    def page_click_task_end(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_end))
        self.base_click(page.task_end)

    #悬停...
    def page_move_to_task_more(self):
        self.base_move_to_element(page.task_more)

    #点击删除任务
    def page_click_task_delete(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_delete))
        self.base_click(page.task_delete)

    #结束任务和删除任务的确认按钮
    def page_click_confirm(self):
        log.info("[page_edit_data]:正在对{}元素进行点击操作".format(page.task_end_confirm))
        self.base_click(page.task_end_confirm)


    #组合业务 任务没开始时进行的数据上传
    def task_no_start_and_data_add(self,filepath):
        self.page_click_add_data()
        time.sleep(2)
        self.page_click_text_confirm()
        time.sleep(2)
        self.add_data_input_filepath(filepath)
        time.sleep(2)
        self.page_click_data_confirm()
        time.sleep(2)

    #组合业务 任务开始后进行的数据上传
    def task_start_and_data_add(self,filepath):
        self.page_task_start_click_add_data()
        time.sleep(2)
        self.page_task_start_click_text_confirm()
        time.sleep(2)
        self.add_data_input_filepath(filepath)
        time.sleep(2)
        self.page_click_data_confirm()
        time.sleep(2)


    #数据上传完成后,进行数据清空操作
    def data_add_success_and_data_clear(self,filepath):
        self.task_no_start_and_data_add(filepath)
        time.sleep(2)
        self.page_click_data_clear()
        time.sleep(2)
        self.page_click_data_clear_confirm()
        time.sleep(2)

    #组合业务 数据上传后填写答题时间和标注团队，点击开始任务
    def data_add_and_start_task(self,filepath,countdown,team_name):
        self.task_no_start_and_data_add(filepath)
        time.sleep(2)
        self.page_input_answer_countdown(countdown)
        time.sleep(2)
        self.page_click_answer_team(team_name)
        # self.page_click_answer_team()
        time.sleep(2)
        self.page_click_start_task()
        time.sleep(1)

    #数据上传成功并且开始任务成功
    def data_add_success_and_start_task_success(self,filepath=page.data_file_path,countdown=1,team_name="标注小组1"):
        self.task_no_start_and_data_add(filepath)
        time.sleep(1)
        self.page_input_answer_countdown(countdown)
        time.sleep(1)
        self.page_click_answer_team(team_name)
        # self.page_click_answer_team()
        time.sleep(1)
        self.page_click_start_task()
        time.sleep(1)

    #组合业务 修改标注团队
    def edit_answer_team(self):
        self.page_click_team_edit()
        time.sleep(2)
        self.page_click_answer_team("默认团队")
        time.sleep(2)
        self.page_click_team_edit_confirm()
        time.sleep(2)

    #组合业务 进行统计分析
    def data_analyse(self):
        self.page_click_analyse()
        time.sleep(2)
        self.page_click_conversation(1)
        time.sleep(2)
        self.page_click_conversation(2)
        time.sleep(2)
        self.page_click_content_conversation()
        time.sleep(2)
        self.page_click_data_filter()
        time.sleep(2)
        self.page_click_result(2)
        time.sleep(2)
        self.page_click_frame_select(1)
        time.sleep(2)
        self.page_click_task_selection("针对整段内容/对话")
        time.sleep(2)
        self.page_click_frame_select(2)
        time.sleep(2)
        self.page_click_task_selection("对话类型")
        time.sleep(2)
        self.page_click_frame_select(3)
        time.sleep(2)
        self.page_click_task_selection("均一致")
        time.sleep(2)
        self.page_click_result(1)
        time.sleep(2)
        self.page_click_frame_select(1)
        time.sleep(2)
        self.page_click_task_selection("针对整段内容/对话")
        time.sleep(2)
        self.page_click_frame_select(2)
        time.sleep(2)
        self.page_click_task_selection("对话质量评估")
        time.sleep(2)
        self.page_click_frame_select(3)
        time.sleep(2)
        self.page_click_task_selection("优秀")
        time.sleep(2)
        self.page_click_close_analyse()
        time.sleep(2)

    #组合业务 查看题目
    def check_question(self):
        self.page_move_to_check_question()
        time.sleep(2)
        self.page_click_single_question()
        time.sleep(2)
        window=self.base_save_original_window()
        time.sleep(2)
        self.base_switch_to_window()
        time.sleep(2)
        self.page_click_close_content_compare()
        time.sleep(2)
        self.page_click_change_subject()
        time.sleep(2)
        self.driver.close()
        self.base_switch_to_original_window(window)
        time.sleep(2)


    #任务开始后进行查看
    def task_start_and_check_task(self,filepath):
        self.page_click_export_config()
        time.sleep(2)
        self.task_start_and_data_add(filepath)
        time.sleep(2)
        self.edit_answer_team()
        time.sleep(2)
        self.data_analyse()
        time.sleep(2)
        self.check_question()
        time.sleep(2)
        self.page_move_to_download()
        time.sleep(2)
        self.page_click_export_downloads()
        time.sleep(2)
        self.page_click_task_end()
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(2)
        self.page_move_to_task_more()
        time.sleep(2)
        self.page_click_task_delete()
        time.sleep(2)
        self.page_click_confirm()
        time.sleep(2)
